package com.shanghaiyimu.yimiyangche.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.adapter.HotFragmentViewPagerAdapter;
import com.shanghaiyimu.yimiyangche.fragment.DaiFukuanFragment;
import com.shanghaiyimu.yimiyangche.fragment.DaianzhuangFragment;
import com.shanghaiyimu.yimiyangche.fragment.DaipingjiaFragment;
import com.shanghaiyimu.yimiyangche.fragment.DaishouhuoFragment;
import com.shanghaiyimu.yimiyangche.fragment.QuanBuDingdanFragment;

import java.util.ArrayList;
import java.util.List;

public class QuanBudingdanActivity extends AppCompatActivity {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<String> titleList;
    private List<Fragment> fragmentList;
    private Fragment f1,f2,f3,f4,f5;
    private HotFragmentViewPagerAdapter adapter;
    private FragmentManager manager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quan_budingdan);
        initView();
        initDaTa();
    }

    private void initView() {
        tabLayout = (TabLayout) findViewById(R.id.dingdan_tablayput);
        viewPager = (ViewPager) findViewById(R.id.dingdan_viewpager);

        manager = getSupportFragmentManager();
        f1 = new QuanBuDingdanFragment();
        f2 = new DaiFukuanFragment();
        f3 = new DaishouhuoFragment();
        f4 = new DaianzhuangFragment();
        f5 = new DaipingjiaFragment();
    }

    private void initDaTa() {
        fragmentList = new ArrayList<>();
        fragmentList.add(f1);
        fragmentList.add(f2);
        fragmentList.add(f3);
        fragmentList.add(f4);
        fragmentList.add(f5);

        titleList = new ArrayList<>();
        titleList.add("全部");
        titleList.add("待付款");
        titleList.add("待收货");
        titleList.add("待安装");
        titleList.add("带评论");

        adapter = new HotFragmentViewPagerAdapter(manager,fragmentList,titleList);
        viewPager.setAdapter(adapter);

        //设置tab的模式
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        //添加tab选项卡
        for (int i = 0; i < titleList.size(); i++) {
            tabLayout.addTab(tabLayout.newTab().setText(titleList.get(i)));
        }
        //把TabLayout和ViewPager关联起来
        tabLayout.setupWithViewPager(viewPager);
    }


}
